package com.yiyahui.project.erp.controller;

import java.util.List;

import com.yiyahui.common.utils.poi.ExcelUtil;
import com.yiyahui.framework.aspectj.lang.annotation.Log;
import com.yiyahui.framework.aspectj.lang.enums.BusinessType;
import com.yiyahui.framework.web.controller.BaseController;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.framework.web.page.TableDataInfo;
import com.yiyahui.project.erp.domain.YiyaDeductProgram;
import com.yiyahui.project.erp.service.IYiyaDeductProgramService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 划扣方案Controller
 * 
 * @author yiyahui
 * @date 2020-05-12
 */
@Api("划扣方案")
@RestController
@RequestMapping("/erp/program")
public class YiyaDeductProgramController extends BaseController
{
    @Autowired
    private IYiyaDeductProgramService yiyaDeductProgramService;
 
    /**
     * 查询划扣方案列表
     */
    @ApiOperation("查询划扣方案列表")
    @PreAuthorize("@ss.hasPermi('erp:program:list')")
    @GetMapping("/list")
    public TableDataInfo list(YiyaDeductProgram yiyaDeductProgram)
    {
        startPage();
        List<YiyaDeductProgram> list = yiyaDeductProgramService.selectYiyaDeductProgramList(yiyaDeductProgram);
        return getDataTable(list);
    }

    /**
     * 导出划扣方案列表
     */
    @ApiOperation("导出划扣方案列表")
    @PreAuthorize("@ss.hasPermi('erp:program:export')")
    @Log(title = "划扣方案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YiyaDeductProgram yiyaDeductProgram)
    {
        List<YiyaDeductProgram> list = yiyaDeductProgramService.selectYiyaDeductProgramList(yiyaDeductProgram);
        ExcelUtil<YiyaDeductProgram> util = new ExcelUtil<YiyaDeductProgram>(YiyaDeductProgram.class);
        return util.exportExcel(list, "program");
    }

    /**
     * 获取划扣方案详细信息
     */
    @ApiOperation("获取划扣方案详细信息")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:program:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yiyaDeductProgramService.selectYiyaDeductProgramById(id));
    }

    /**
     * 新增划扣方案
     */
    @ApiOperation("新增划扣方案")
    @ApiImplicitParam(name = "yiyaDeductProgram", value = "${tableComment}", dataType = "YiyaDeductProgram")
    @PreAuthorize("@ss.hasPermi('erp:program:add')")
    @Log(title = "划扣方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YiyaDeductProgram yiyaDeductProgram)
    {
        return toAjax(yiyaDeductProgramService.insertYiyaDeductProgram(yiyaDeductProgram));
    }

    /**
     * 修改划扣方案
     */
    @ApiOperation("修改划扣方案")
    @ApiImplicitParam(name = "yiyaDeductProgram", value = "${tableComment}", dataType = "YiyaDeductProgram")
    @PreAuthorize("@ss.hasPermi('erp:program:edit')")
    @Log(title = "划扣方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YiyaDeductProgram yiyaDeductProgram)
    {
        return toAjax(yiyaDeductProgramService.updateYiyaDeductProgram(yiyaDeductProgram));
    }

    /**
     * 删除划扣方案
     */
    @ApiOperation("删除划扣方案")
    @ApiImplicitParam(name = "ids", value = "主键id数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:program:remove')")
    @Log(title = "划扣方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yiyaDeductProgramService.deleteYiyaDeductProgramByIds(ids));
    }
}
